]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
na-tray-child: Use absolute icon position as root event coordinates
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 25 Apr 2024 15:13:34 +0000 (17:13 +0200)
committerMarge Bot <marge-bot@gnome.org>
Mon, 29 Apr 2024 16:50:13 +0000 (16:50 +0000)
Currently we're using relative positioning when sending click events to
tray icon clients, and this leads to some apps (especially Qt ones) to
try to open the menus at such absolute coordinate under X11.

To prevent this to happen, let's get the root coordinate from the xembed
and let's use it to compute the synthetic event root x/y.

We could have even used the actual event position for this, but getting
it from the xembed makes this more consistent.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3283>

src/tray/na-tray-child.c
src/tray/na-xembed.c
src/tray/na-xembed.h

index 53a66cee755793c1f65a7b0b7ed878a6cf28ee48..091199574352d3cc2bc8563283b3da927dc09ea2 100644 (file)
@@ -267,6 +267,7 @@ na_tray_child_emulate_event (NaTrayChild *tray_child,
   Window xwindow, xrootwindow;
   ClutterEventType event_type = clutter_event_type (event);
   int width, height;
+  int root_x, root_y;
 
   g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE ||
                     event_type == CLUTTER_KEY_PRESS ||
@@ -283,6 +284,7 @@ na_tray_child_emulate_event (NaTrayChild *tray_child,
     }
 
   na_xembed_get_size (NA_XEMBED (tray_child), &width, &height);
+  na_xembed_get_root_position (NA_XEMBED (tray_child), &root_x, &root_y);
 
   mtk_x11_error_trap_push (xdisplay);
   xrootwindow = XDefaultRootWindow (xdisplay);
@@ -295,8 +297,8 @@ na_tray_child_emulate_event (NaTrayChild *tray_child,
   xcevent.time = clutter_event_get_time (event);
   xcevent.x = width / 2;
   xcevent.y = height / 2;
-  xcevent.x_root = xcevent.x;
-  xcevent.y_root = xcevent.y;
+  xcevent.x_root = root_x + xcevent.x;
+  xcevent.y_root = root_y + xcevent.y;
   xcevent.mode = NotifyNormal;
   xcevent.detail = NotifyNonlinear;
   xcevent.same_screen = True;
index 8f785305aadcd409e719c6705848485ca2b946e3..59b1071b80eaf7b4d861e0f2eba5f1a29a0144e8 100644 (file)
@@ -796,6 +796,19 @@ na_xembed_get_size (NaXembed *xembed,
     *height = priv->request_height;
 }
 
+void
+na_xembed_get_root_position (NaXembed *xembed,
+                             int      *x,
+                             int      *y)
+{
+  NaXembedPrivate *priv = na_xembed_get_instance_private (xembed);
+
+  if (x)
+    *x = priv->root_x;
+  if (y)
+    *y = priv->root_y;
+}
+
 static void
 get_pixel_details (unsigned long  pixel_mask,
                    int           *shift,
index ec46119d4def1acd8f908c7f9e6daa37a2bfaaf3..ea8f9f44c2c87ec59f017f83b446131854fb96f0 100644 (file)
@@ -51,6 +51,10 @@ void na_xembed_set_root_position (NaXembed *xembed,
                                  int       x,
                                  int       y);
 
+void na_xembed_get_root_position (NaXembed *xembed,
+                                 int      *x,
+                                 int      *y);
+
 void na_xembed_get_size (NaXembed *xembed,
                         int      *width,
                         int      *height);